<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id="app">

  </div>
  <style>
    .box {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      width: 300px;
      height: 300px;
      background-color: aqua;
      z-index: 10;
    }

    .mask {
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      background-color: #000;
      opacity: .5;
    }
  </style>
  <script src="https://unpkg.com/vue@next"></script>
  <script>
    // 创建一个vue实例
    const app = Vue.createApp({
      data() {
        return {
          // count:1,
          distance: 200,
          show: false
        }
      },
      template: `
        <div class="box">
          <button  @click='clickBtn'>点击</button>
          // to 指定挂在的元素位置
          <teleport to="body">
            <div v-show="show" class="mask">
            
            </div>
          </teleport>
        </div>
      `,
      mounted() {
        // this.$refs.input.focus();
      },
      methods: {
        clickBtn() {
          this.show = !this.show;
        }
      }
    })
    app.mount("#app");
  </script>
</body>

</html>